package com.kaiwukj.android.ufamily.mvp.ui.page.home.home;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.ActiveResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.CommunityInfoResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.CommunityNewResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.CommunityNoticeResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.DynamicResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.FriendRecoResult;

import java.util.ArrayList;
import java.util.List;

public class HomeMultiItemEntity implements MultiItemEntity {


    public static final int HOME_NOTICE = 1;//通知
    public static final int HOME_ACTIVE = 2;//活动
    public static final int HOME_DYNAMIC = 3;//动态
    public static final int HOME_FRIEND_RECOMMEND = 4;//推荐好友
    public static final int HOME_BANNER = 5;//banner
    public static final int HOME_COMMUNITY_NEWS = 6;//社区资讯
    public static final int HOME_FRIEND_RECOMMEND_BETA = 7;//社区资讯


    private int itemType;

    public HomeMultiItemEntity(int itemType) {
        this.itemType = itemType;
    }

    @Override
    public int getItemType() {
        return itemType;
    }

    private CommunityInfoResult communityInfo;
    private CommunityNoticeResult notice;
    private List<ActiveResult> actives;
    private DynamicResult dynamicResult;
    private List<FriendRecoResult> friendList;
    private List<CommunityNewResult> communityNews;

    public CommunityInfoResult getCommunityInfo() {
        return communityInfo;
    }

    public void setCommunityInfo(CommunityInfoResult communityInfo) {
        this.communityInfo = communityInfo;
    }

    public CommunityNoticeResult getNotice() {
        return notice;
    }

    public void setNotice(CommunityNoticeResult notice) {
        this.notice = notice;
    }

    public List<ActiveResult> getActives() {
        return actives;
    }

    public void setActives(List<ActiveResult> actives) {
        this.actives = actives;
    }

    public DynamicResult getDynamicResult() {
        return dynamicResult;
    }

    public void setDynamicResult(DynamicResult dynamicResult) {
        this.dynamicResult = dynamicResult;
    }

    public List<FriendRecoResult> getFriendList() {
        return friendList;
    }

    public void setFriendList(List<FriendRecoResult> friendList) {
        this.friendList = friendList;
    }


    public List<CommunityNewResult> getCommunityNews() {
        return communityNews;
    }

    public void setCommunityNews(List<CommunityNewResult> communityNews) {
        this.communityNews = communityNews;
    }

    public int getItemCount() {
        switch (getItemType()) {
            case HOME_ACTIVE:
                return getActives() == null ? 0 : getActives().size();
            case HOME_FRIEND_RECOMMEND:
            case HOME_FRIEND_RECOMMEND_BETA:
                return getFriendList() == null ? 0 : getFriendList().size();
            case HOME_COMMUNITY_NEWS:
                return getCommunityNews() == null ? 0 : getCommunityNews().size();

            default:
                return 0;
        }
    }

    public static List<HomeMultiItemEntity> getDynamicResults(List<DynamicResult> dynamicResults) {
        if (dynamicResults == null) return new ArrayList<>();
        List<HomeMultiItemEntity> list = new ArrayList<>();
        for (DynamicResult result : dynamicResults) {
            HomeMultiItemEntity entity = new HomeMultiItemEntity(HomeMultiItemEntity.HOME_DYNAMIC);
            entity.setDynamicResult(result);
            list.add(entity);
        }
        return list;
    }
}
